
********************************************************************************
****************************** Finacial variables ******************************
********************************************************************************
// Many of these variables are already created as I don�t have the permit to spread the original data provided by Statistic Sweden. I provide the scrip in order to show how they where created.
// Data can be obtained from Statistics Sweden SCB.SE 

// Generating the share of finacial or risky assets (Finacial wealth to total wealth ratio)
*gen Finacial_share =  (Value_stock + Value_mixedfund + Value_bondfund) / ( Value_house + Value_apartment + Value_stock + Value_mixedfund + Value_bondfund ) if Year == 1998
*replace Finacial_share =  l.Finacial_share if Year != 1998
*hist Finacial_share, freq

// Finacial wealth per voter or adult citizens (Finacial wealth divided by the number of elegible voters)
*gen FWPV = (Value_stock+ Value_mixedfund+ Value_bondfund)/VV if Year == 1998
*replace  FWPV = l.FWPV if Year > 1998

// Owners to voters of assets in 1998 (Number of owners to elegible voters)
*gen Owners98 = (Owners_stock/VV+Owners_mixedfund/VV+Owners_bondfund/VV)/3
*replace Owners98 = l.Owners98 if Year > 1998

// Ownership as a total share of Sweden
*gen Finance98 = (  Value_stock+ Value_mixedfund+ Value_bondfund) if Year == 1998
*egen sumfin = sum(Finance98)
*gen Share_Finance98= Finance98 / sumfin
*replace Share_Finance98 = l.Share_Finance98 if Year > 1998

// Inequality meassured as the ratio of wealth per owner to wealth to voters
*gen Inequality = ((Value_stock /Owners_stock)/(Value_stock/Voters)+ (Value_mixedfund/Owners_mixedfund)/(Value_mixedfund/Voters) + (Value_bondfund/Owners_bondfund)/(Value_bondfund/Voters)) / 3 if Year == 1998
*replace Inequality = l.Inequality if Year > 1998 

// Housing wealth per voter
*gen hwpo = (Value_house / Voters) / 100000 if Year == 1998
*replace hwpo = l.hwpo if Year > 1998
*label variable hwpo "Hosuing wealth per voter in 1998"

 *Generate growth on housing wealth
*gen GHW = d.Value_house / l.Value_house if Year < 2010
*replace GHW = d.Price / l.Price if Year > 2006
*replace GHW = 0 if GHW ==.

// Skapar local returns on housing 
gen Hosuing_returns = GHW * hwpo

// Independent variable
gen Risk = d.Vix * Finacial_share

// Risk variable weighted by the share of owners
gen Risk_po = Risk*Owners98

// Weaght the finacial share with the share of owners
gen Finacial_share_po = Finacial_share * Owners98


********************************************************************************
****************************** Political parties *******************************
********************************************************************************

// R�standelar politiska partier 
* Social Democrats:
gen Share_S = (s/ VV) * 100
label variable Share_S "Vote share Social democratic party"
* Left-party: 
gen Share_V =( v / VV) * 100
label variable Share_V "Vote share Left party"
* Green party:
gen Share_MP = (mp  / VV) * 100
label variable Share_MP "Vote share Green party"
* Moderate party:
gen Share_M = (m  / VV) * 100
label variable Share_M "Vote share Moderate party"
* Liberal party:
gen Share_L = (fp / VV) * 100
label variable Share_L "Vote share Liberal party"
* Center party:
gen Share_C = (c / VV) * 100
label variable Share_C "Vote share Center party"
* Christian democrats:
gen Share_KD  =  (kd / VV) * 100
label variable Share_KD "Vote share Center party"
* Other parties
gen Share_Other = (vr / VV) * 100
label variable Share_Other "Vote share for the category other parties "

//  Left-wing bloc share
gen Left = Share_S + Share_V  + Share_MP
label variable Left "Vote share for the left-wing bloc "
// First diffrence
gen dLeft = d.Left
hist dLeft if Year, freq

// Right-wing bloc share
gen Right = Share_M+Share_L+Share_C+Share_KD
label variable Right "Vote share for the right-wing bloc "
// First diffrence
gen dRight = d.Right
hist dRight, freq

********************************************************************************
**************************** Political coalitions*******************************
********************************************************************************
//  Generatig the right-wing coalition dummy:
gen Right_coalition = 0
replace Right_coalition = 1 if l.incparty_m == 1 & l.incparty_s== 0 & l.incparty_v == 0 & l.incparty_mp == 0
replace Right_coalition = 1 if l.incparty_kd == 1 & l.incparty_s== 0 & l.incparty_v == 0 & l.incparty_mp == 0
replace Right_coalition = 1 if l.incparty_fp == 1 & l.incparty_s== 0 & l.incparty_v == 0 & l.incparty_mp == 0
replace Right_coalition = 1 if l.incparty_c == 1 & l.incparty_s== 0 & l.incparty_v == 0 & l.incparty_mp == 0

// Generating a left-wing coalition dummy
gen Left_coalition = 0
replace Left_coalition = 1 if Right_coalition == 0

// Change in the support for the ruling coalitions: 
gen Incumbent_local = ((d.Share_S*l.incparty_s)+(d.Share_V*l.incparty_v)+(d.Share_MP*l.incparty_mp)+(d.Share_L*l.incparty_fp)+(d.Share_M *l.incparty_m)+(d.Share_C*l.incparty_c)+(d.Share_KD*l.incparty_kd)+(d.Share_Other*l.incparty_oth))
label variable Incumbent_local "Change in support for the ruling coalition"




********************************************************************************
************************** Other Control variables *****************************
********************************************************************************
* Share of non-employed:
gen NP = 1-Sysselsat
label variable NP "Share of workers not employed"

* Age sqaure
gen Agesq = Age * Age
label variable Agesq "Age squared"

* Summary statistics 
sum d.Age d.Education d.Migrant d.LoneInk d.Agesq d.NP
